package oop.controller.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.ObjectUtils;

import oop.controller.ControllerServlet;
import oop.data.User;

public abstract class DefaultAction {

	private ControllerServlet controller;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	private String nextAction = null;
	private boolean preventForward = false;

	public DefaultAction() {
		// NOTHING
	}

	protected boolean isUserLogedIn() {
		return (Boolean) (ObjectUtils.defaultIfNull(request.getSession()
				.getAttribute("login"), Boolean.FALSE));
	}

	protected User getUser() {
		return (User) request.getSession().getAttribute("user");
	}

	public ControllerServlet getController() {
		return controller;
	}

	public void setController(ControllerServlet controller) {
		this.controller = controller;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public abstract void perform() throws Exception;

	protected void setNextAction(String nextAction) {
		this.nextAction = nextAction;
	}

	public String getNextAction() {
		return nextAction;
	}

	protected void setPreventForward(boolean preventForward) {
		this.preventForward = preventForward;
	}

	public boolean isPreventForward() {
		return preventForward;
	}

}
